package com.wufun.overseas.tools.socket;

import android.util.Log;

import com.wufun.overseas.tools.socket.entity.SocketRequestBean;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * Author: hest
 * Date:  2016/4/27
 * 发送消息管理队列
 */
public class RequestQueneManager {
    private static final String TAG=RequestQueneManager.class.getSimpleName();
    LinkedBlockingQueue<SocketRequestBean> mQueueList;
    private static final class Holder{
        public static final RequestQueneManager sINSTANCE = new RequestQueneManager();
    }

    private RequestQueneManager(){
        mQueueList = new LinkedBlockingQueue<SocketRequestBean>();
    }

    public static RequestQueneManager getInstance(){
        return Holder.sINSTANCE;
    }

    //取出
    public SocketRequestBean poll(){
        SocketRequestBean entity = null;
        if(mQueueList != null){
            entity =  mQueueList.poll();
            //Log.d(TAG, "poll: size"+mQueueList.size());
        }
        return entity;
    }

    //装入
    public void push(SocketRequestBean entity){
        try {
            if(mQueueList == null){
                mQueueList = new LinkedBlockingQueue<SocketRequestBean>();
            }
            mQueueList.put(entity);
            Log.d(TAG, "push: 装入数据 size"+mQueueList.size()+entity.toString());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void clearAll(){
        if(mQueueList != null){
            mQueueList.clear();
        }
    }
}
